/*
 * @Author: ChunLai
 * @Date: 2022-09-06 17:03:37
 * @LastEditTime: 2025-07-08 17:01:25
 * @Description: 缓存
 * @FilePath: \01.latest-short-insure\src\methods\cache.js
 */
export const setMessage = (key, value) => {
  let valType = Object.prototype.toString
    .call(value)
    .slice(8, -1)
    .toLowerCase();
  if (valType === "object" || valType === "array") {
    sessionStorage.setItem(key, JSON.stringify(value));
  } else {
    sessionStorage.setItem(key, value);
  }
};

export const getMessage = (key) => {
  let msg = sessionStorage.getItem(key);
  if (msg === null) {
    // 没有存储值
    return msg;
  } else {
    let msgType = msg.substr(0, 1);
    if (msgType === "{" || msgType === "[") {
      return JSON.parse(msg);
    } else {
      return msg;
    }
  }
};

export const getProParams = (key) => {
  const vuexCache = getMessage("ms2024_insure") || {};
  let res = "";
  if (key === "code") {
    res = vuexCache.mainRiskCode;
  } else if (key === "id") {
    res = vuexCache.proIdCode;
  } else if (key === "gys") {
    res = vuexCache.gysEngName;
  } else if (key === "workNum") {
    res = vuexCache.workNum;
  }
  return res;
};
